package LeetCode.exercise;

import java.util.ArrayList;
import java.util.List;

public class LC_118 {
    public static void main(String[] args) {
        System.out.println(generate(5));
    }
    public static List<List<Integer>> generate(int numRows){
        List<List<Integer>> row = new ArrayList<>();
        List<Integer> ret = new ArrayList<>();
        ret.add(1);
        row.add(ret);
        for (int i = 1; i < numRows; i++) {
            List<Integer> preRow = row.get(i-1);
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);  //第一个1
            for (int j = 1; j < i; j++) {
                Integer integer = preRow.get(j) + preRow.get(j-1);
                curRow.add(integer);
            }
            curRow.add(1);  //最后一个1
            row.add(curRow);
        }
        return row;
    }
}
